Slider (2)
Noch eine Variante des Sliders. Diesmal mithilfe einer Windows-OCX-Bibliothek. Der Slider hat keine Beschriftung, hat aber den Vorteil, dass auf eine Wertänderung sofort reagiert werden kann.
Dynpro
Sie müssen das Dynpro 9000 anlegen mit folgenden “Custom Containern”:
- CONTAINER_TEXT
- SLIDER_TOP
- SLIDER_LEFT
+----------------------------------------+
| SLIDER_TOP |
+----+----------------------------------------+
| | |
| SL | CONTAINER_TEXT |
| ID | |
| ER | |
| _ | |
| LE | |
| FT | |
| | |
| | |
+----+----------------------------------------+
Screenshot
So sieht der Slider aus |
Coding
REPORT. DATA: gcl_text TYPE REF TO cl_gui_textedit. *----------------------------------------------------------------------* * CLASS my_slider DEFINITION *----------------------------------------------------------------------* CLASS my_slider DEFINITION INHERITING FROM cl_gui_control. PUBLIC SECTION. METHODS: constructor IMPORTING value(parent) TYPE REF TO cl_gui_object value(name) TYPE string OPTIONAL value(style) TYPE i OPTIONAL value(orientation) TYPE i DEFAULT 0 " 1 = vertical value(maximum) TYPE i DEFAULT 10 value(event_while_move) TYPE flag DEFAULT ' ' EXCEPTIONS error_cntl_create gui_type_not_supported, dispatch REDEFINITION. EVENTS: on_change EXPORTING value(slider_position) TYPE i. DATA: event_while_move TYPE flag. PRIVATE SECTION. METHODS: register_events. ENDCLASS. "my_slider DEFINITION *----------------------------------------------------------------------* * CLASS LCL_eventreceiver DEFINITION *----------------------------------------------------------------------* CLASS lcl_eventreceiver DEFINITION. PUBLIC SECTION. CLASS-METHODS: handle_on_change FOR EVENT on_change OF my_slider IMPORTING sender slider_position. ENDCLASS. "LCL_eventreceiver DEFINITION END-OF-SELECTION. PERFORM create_objects. CALL SCREEN 9000. *&---------------------------------------------------------------------* *& Form CREATE_OBJECTS *&---------------------------------------------------------------------* FORM create_objects. DATA repid TYPE syrepid. DATA dynnr TYPE sydynnr. DATA cl_container TYPE REF TO cl_gui_custom_container. DATA cl_container2 TYPE REF TO cl_gui_custom_container. repid = sy-repid. dynnr = '9000'. CREATE OBJECT cl_container EXPORTING container_name = 'CONTAINER_TEXT' repid = repid dynnr = dynnr. CREATE OBJECT gcl_text EXPORTING parent = cl_container. DATA: cl_slider TYPE REF TO my_slider. CREATE OBJECT cl_container EXPORTING container_name = 'SLIDER_TOP' repid = repid dynnr = dynnr. CREATE OBJECT cl_slider EXPORTING parent = cl_container maximum = 20 event_while_move = 'X'. SET HANDLER lcl_eventreceiver=>handle_on_change FOR cl_slider. CREATE OBJECT cl_container EXPORTING container_name = 'SLIDER_LEFT' repid = repid dynnr = dynnr. CREATE OBJECT cl_slider EXPORTING parent = cl_container maximum = 5 orientation = 1. SET HANDLER lcl_eventreceiver=>handle_on_change FOR cl_slider. ENDFORM. " CREATE_OBJECTS *----------------------------------------------------------------------* * CLASS my_slider IMPLEMENTATION *----------------------------------------------------------------------* CLASS my_slider IMPLEMENTATION. METHOD dispatch. DATA: value TYPE i. GET PROPERTY OF me->h_control-obj 'Value' = value. RAISE EVENT on_change EXPORTING slider_position = value. ENDMETHOD. "dispatch METHOD register_events. DATA: ex_event TYPE cntl_event. DATA: events_ex TYPE cntl_events. " table IF me->event_while_move = 'X'. ex_event-eventid = 1."Jede Bewegung ELSE. ex_event-eventid = 2."Nur am ende ENDIF. ex_event-is_shellevent = ' '. ex_event-is_systemevent = 'X'. APPEND ex_event TO events_ex. CALL METHOD me->set_registered_events_ex EXPORTING eventtab = events_ex. ENDMETHOD. "register_events METHOD constructor. DATA prog_id(80). IF parent IS INITIAL. RAISE error_cntl_create. ENDIF. CLASS cl_gui_cfw DEFINITION LOAD. * assign prog_id to get the frontend specific control IF NOT activex IS INITIAL. prog_id = 'MSComctlLib.Slider'. ELSEIF NOT javabean IS INITIAL. RAISE gui_type_not_supported. ENDIF. IF prog_id IS INITIAL. RAISE gui_type_not_supported. ENDIF. * Set the window styles of the control when style parameter was not * set with constructor call. * For more information on the styles see WIN32 SDK IF style IS INITIAL. * otherwise the control would be invisible and the mistake would be * hard to find style = cl_gui_control=>ws_visible + cl_gui_control=>ws_child + cl_gui_control=>ws_clipsiblings. ENDIF. * Create the control CALL METHOD super->constructor EXPORTING clsid = prog_id shellstyle = style parent = parent lifetime = lifetime name = name EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. RAISE error_cntl_create. ENDIF. me->event_while_move = event_while_move. * Slidereigenschaften SET PROPERTY OF me->h_control-obj 'Max' = maximum. SET PROPERTY OF me->h_control-obj 'Orientation' = orientation. SET PROPERTY OF me->h_control-obj 'Text' = 'Tricktresor-Slider'. * register instance at framework CALL METHOD cl_gui_cfw=>subscribe EXPORTING shellid = h_control-shellid ref = me EXCEPTIONS OTHERS = 1. IF sy-subrc <> 0. RAISE error_cntl_create. ENDIF. me->register_events( ). ENDMETHOD. "constructor ENDCLASS. "my_slider IMPLEMENTATION *----------------------------------------------------------------------* * CLASS LCL_eventreceiver DEFINITION *----------------------------------------------------------------------* CLASS lcl_eventreceiver IMPLEMENTATION. METHOD handle_on_change. DATA text TYPE string. DATA: slider TYPE REF TO my_slider. slider ?= sender. WRITE slider_position TO sy-lisel LEFT-JUSTIFIED. IF slider->event_while_move = 'X'. CONCATENATE 'X-Position: Moving to' sy-lisel INTO text SEPARATED BY space. ELSE. CONCATENATE 'Y-Position: End of Move:' sy-lisel INTO text SEPARATED BY space. ENDIF. gcl_text->set_textstream( EXPORTING text = text ). ENDMETHOD. "handle_on_change ENDCLASS. "LCL_eventreceiver DEFINITION
- Interview mit Björn Schulz (Software-Heroes.com) - 3. September 2024
- Daten aus ALV ermitteln - 3. September 2024
- So lange es den SAPGUI noch gibt… - 27. Juni 2024